<template>
	<view v-if="dataOk">
		<view class="fold-icon" v-if="!disableData.includes('app_fold')">
			<image src="../../../../../static/images/icon/arrow-down.png" v-if="showFold" @click="clickIcon"></image>
			<image src="../../../../../static/images/icon/arrow-up.png" v-if="!showFold" @click="clickIcon"></image>
		</view>
		<scroll-view scroll-y="true"  :class="isView ? '' : disableData.includes('app_fold') ? 'scroll-height' : 'scroll-height-fold'">
			<view v-if="!showFold">
				<view class="condition">
					<view class="contexts" v-if="!disableData.includes('locaName')">
						<view class="loca-select">
							<view class="conleft">{{$t('defect.common.locaName')}}<span class="redx">*</span></view>
							<view class="conright" v-if="!judgeBase">
								<button type="primary" size="mini" @click="scanLoca">{{$t('baseCommon.buttons.scan')}}</button>
								<button type="primary" size="mini" @click="selectLoca">{{$t('common.buttons.choice')}}</button>
							</view>
						</view>
						<view class="contopright">
							<textarea disabled v-model="data.locaName" :placeholder="$t('baseCommon.message.nfcOrScanOrSel')" auto-height />
						</view>
					</view>
				</view>
				<view class="condition">
					<view class="conmenus" v-if="!disableData.includes('dfLevel')">
						<view class="conleft">{{$t('defect.common.defectLev')}}<span class="redx">*</span></view>
						<view class="conright">
							<data-picker v-model="data.dfLevelNo" :range="levelList" :disabled="judgeBase" @change="selectLevel"></data-picker>
						</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('dfType')">
						<view class="conleft">{{$t('defect.defInfo.dfType')}}<span class="redx">*</span></view>
						<view class="conright">
							<data-picker v-model="data.dfType" :range="typeList" :disabled="judgeBase" @change="typeChange"></data-picker>
						</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('skillNo')">
						<view class="conleft">{{$t('baseCommon.other.skillNo')}}<span class="redx">*</span></view>
						<view class="conright">
							<data-picker v-model="data.skillNo" :range="skillList" :disabled="judgeBase"></data-picker>
						</view>
					</view>
					<view v-if="!disableData.includes('dfDesp')">
						<view class="contexts" v-if="!judgeBase && dfFaultKnowledge">
							<view class="loca-select">
								<view class="conleft">{{$t('defect.common.defectCom')}}<span class="redx">*</span></view>
								<view class="conright" v-if="!judgeBase">
									<button type="primary" size="mini" class="loca-btn" @click="selectPhenomenon">{{$t('defect.defInfo.oldFaultDescription')}}</button>
								</view>
							</view>
							<view class="contopright">
								<textarea v-model="data.dfDesp" :placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" 
									auto-height :disabled="judgeBase" />
							</view>
						</view>
						<view class="contexts" v-else>
							<view class="conleft">{{$t('defect.common.defectCom')}}<span class="redx">*</span></view>
							<view class="contopright">
								<textarea v-model="data.dfDesp" :placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" 
									auto-height :disabled="judgeBase" />
							</view>
						</view>
					</view>
					<template v-if="showAnalysis">
						<view class="contexts" v-if="!disableData.includes('oldFaultDescription') && dfFaultKnowledge">
							<view class="conleft">{{$t('defect.defInfo.oldFaultDescription')}}</view>
							<view class="contopright">
								<textarea disabled :placeholder="$t('baseCommon.message.pleaseSelect', { title: '' })" v-model="data.oldFaultDescription" 
									auto-height @click="!editData.includes('oldFaultDescription')?'':selectPhenomenon()"/>
							</view>
						</view>
						<view class="contexts" v-if="!disableData.includes('oldReasonAnalysis')">
							<view class="conleft">{{$t('defect.defInfo.defReasonAnalysis')}}<span class="redx">*</span></view>
							<view class="contopright">
								<textarea :placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" v-model="data.oldReasonAnalysis" 
									auto-height :disabled="isView || !editData.includes('oldReasonAnalysis')"/>
							</view>
						</view>
						<view class="contexts" v-if="!disableData.includes('oldTreatmentMeasure')">
							<view class="conleft">{{$t('defect.defInfo.defTreatmentMeasure')}}<span class="redx">*</span></view>
							<view class="contopright">
								<textarea :placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" v-model="data.oldTreatmentMeasure" 
									auto-height :disabled="isView || !editData.includes('oldTreatmentMeasure')"/>
							</view>
						</view>
						<view class="conmenus" v-if="!disableData.includes('oldStdWoName') && dfWorkOrder">
							<view class="conleft">{{$t('defect.defInfo.oldStdWoName')}}</view>
							<view class="conright">
								<input disabled :placeholder="$t('baseCommon.message.pleaseSelect', { title: '' })" v-model="data.oldStdWoName"
									@click="editData.includes('oldStdWoName')?selectStdWo():''"/>
							</view>
						</view>
					</template>
				</view>
				<view class="condition">
					<view class="conmenus" v-if="!disableData.includes('findperson')">
						<view class="conleft shortleft">{{$t('defect.defInfo.findperson')}}<span class="redx">*</span></view>
						<view class="conright fieldSplice">
							<input @click="judgeBase?'':selectUser('find')" disabled :placeholder="$t('baseCommon.message.pleaseSelect', { title: '' })" v-model="data.findperson" />
							<view class="separator">|</view>
							<view class="fieldView">{{data.findTeamName}}</view> 
						</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('finddate')">
						<view class="conleft">{{$t('defect.defInfo.disTime')}}</view>
						<view class="conright">
							<date-picker mode="dateTime" :showValue="data.finddate" :disabled="judgeBase" @change="dateChange($event, 'finddate')">
								{{ data.finddate || $t('baseCommon.message.pleaseSelect', { title: '' }) }}
							</date-picker>
						</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('mtnTeamName')">
						<view class="conleft">{{$t('defect.defInfo.mtnTeamName')}}<span class="redx">*</span></view>
						<view class="conright">
							<data-picker v-model="data.mtnTeamNo" :range="teamList" :disabled="judgeBase" @change="teamChange"></data-picker>
						</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('mtnPerson')">
						<view class="conleft">{{$t('defect.defInfo.xqMtnPerson')}}</view>
						<view class="conright">
							<input disabled :placeholder="$t('baseCommon.message.pleaseSelect', { title: '' })" v-model="data.mtnPerson"
								@click="judgeBase&&!editData.includes('mtnPerson')?'':selectUser('solve')"/>
						</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('planEndTime')">
						<view class="conleft">{{$t('defect.defInfo.planEndTime')}}<span class="redx">*</span></view>
						<view class="conright">
							<date-picker mode="dateTime" :showValue="data.planEndTime" :disabled="judgeBase&&!editData.includes('planEndTime')" @change="dateChange($event, 'planEndTime')">
								{{ data.planEndTime || $t('baseCommon.message.pleaseSelect', { title: '' }) }}
							</date-picker>
						</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('noticeperson')">
						<view class="conleft">{{$t('defect.defInfo.noticeperson')}}</view>
						<view class="conright">
							<input disabled :placeholder="$t('baseCommon.message.pleaseSelect', { title: '' })" v-model="data.noticeperson" 
								@click="!isView && editData.includes('noticeperson')?selectUserMulti('notice'):''"/>
						</view>
					</view>
				</view>
			</view>
			<view v-if="showFold">
				<view class="condition">
					<view class="contexts">
						<view class="conleft">{{$t('defect.common.locaName')}}</view>
						<view class="coninputright">
							{{data.locaName}}
						</view>
					</view>
					<view class="contexts">
						<view class="conleft">{{$t('defect.common.defectCom')}}</view>
						<view class="coninputright">
							{{data.dfDesp}}
						</view>
					</view>
					<template v-if="showAnalysis">
						<view class="contexts">
							<view class="conleft">{{$t('defect.defInfo.defReasonAnalysis')}}</view>
							<view class="coninputright">
								{{data.oldReasonAnalysis}}
							</view>
						</view>
						<view class="contexts">
							<view class="conleft">{{$t('defect.defInfo.defTreatmentMeasure')}}</view>
							<view class="coninputright">
								{{data.oldTreatmentMeasure}}
							</view>
						</view>
					</template>
					<view class="conmenus">
						<view class="conleft">{{$t('defect.defInfo.planEndTime')}}</view>
						<view class="conright">
							{{data.planEndTime}}
						</view>
					</view>
				</view>
			</view>
			
			<view class="label" v-if="isApprove && !disableData.includes('xqForm')">
				<view class="label-content">
					<view class="label-title">
						<view class="label-mark"></view>
						<text>{{$t('defect.common.defHandle')}}</text>
					</view>
					<view class="label-btn">
						<button type="primary" size="mini" v-if="pageTicket && !disableData.includes('wtWorkTktInv')" @click="applyTicket">{{$t('common.buttons.ticket')}}</button>
					</view>
				</view>
				<view class="condition" v-if="!disableData.includes('app_fold')">
					<view class="conmenus" v-if="!disableData.includes('clearDate')">
						<view class="conleft">{{$t('defect.defInfo.clearTime')}}</view>
						<view class="conright">
							<date-picker mode="dateTime" :showValue="data.clearDate" :disabled="isView || !editData.includes('clearDate')" @change="dateChange($event, 'clearDate')">
								{{ data.clearDate || $t('baseCommon.message.pleaseSelect', { title: '' }) }}
							</date-picker>
						</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('chooseTimeType')">
						<view class="conleft">{{$t('defect.defInfo.chooseTimeType')}}</view>
						<view class="conright">
							<data-picker v-model="data.chooseTimeType" :range="hangTimeList" :disabled="!editData.includes('chooseTimeType')"></data-picker>
						</view>
					</view>
					<view class="contexts" v-if="!disableData.includes('maintenanceExplain')">
						<view class="conleft">{{$t('defect.defInfo.maintenanceExplain')}}</view>
						<view class="contopright">
							<textarea :placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" maxlength="-1" auto-height v-model="data.maintenanceExplain"
								:disabled="!editData.includes('maintenanceExplain')"/>
						</view>
					</view>
					<view class="conmenus" v-if="dfMaterial">
						<view class="conleft">{{$t('defect.defInfo.isReplace')}}<span class="redx">*</span></view>
						<view class="conright">
							<radio-group @change="radioChange($event, 'replace')">
								<label class="radio-label" v-for="item in radioList" :key="item.value">
									<view>
										<radio class="radio-item" :value="item.value" :checked="item.value == data.isReplace" 
											:disabled="isView || !editData.includes('isReplace')"/>
									</view>
									<view>{{item.label}}</view>
								</label>
							</radio-group>
						</view>
					</view>
				</view>
			</view>
			<view class="label" v-if="!disableData.includes('ysxx')">
				<view class="label-content">
					<view class="label-title">
						<view class="label-mark"></view>
						<text>{{$t('defect.common.acceptInfo')}}</text>
					</view>
				</view>
				<view class="condition">
					<view class="conmenus" v-if="!disableData.includes('isDefect')">
						<view class="conleft">{{$t('defect.defInfo.isDefect')}}</view>
						<view class="conright">
							<radio-group @change="radioChange">
								<label class="radio-label" v-for="item in radioList" :key="item.value">
									<view>
										<radio class="radio-item" disabled :value="item.value" :checked="item.value === data.isDefect" />
									</view>
									<view>{{item.label}}</view>
								</label>
							</radio-group>
						</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('validateUserName')">
						<view class="conleft">{{$t('defect.defInfo.validateUserName')}}</view>
						<view class="conright">{{data.validateUserName}}</view>
					</view>
					<view class="conmenus" v-if="!disableData.includes('validateTime')">
						<view class="conleft">{{$t('defect.defInfo.validateTime')}}</view>
						<view class="conright">{{data.validateTime}}</view>
					</view>
					<view class="contexts" v-if="!disableData.includes('evaluateDesc')">
						<view class="conleft">{{$t('defect.defInfo.evaluateDesc')}}</view>
						<view class="contopright">
							<textarea :placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" v-model="data.evaluateDesc" 
								auto-height :disabled="isView || !editData.includes('evaluateDesc')"/>
						</view>
					</view>
				</view>
			</view>
			<view class="condition" v-if="!disableData.includes('app_change')">
				<view v-for="(item, index) in data.changeList" :key="index">
					<view class="list-area" v-if="item.changeType == 'sqys'">
						<view class="list-type">
							<view class="type">{{$t('defect.common.accept')}}</view>
						</view>
						<view class="list-info">
							<view>
								<text class="info-title">{{$t('defect.defInfo.finishTime')}}：</text>
								<text class="info-desc">{{item.changeTime}}</text>
							</view>
							<view>
								<text class="info-title">{{$t('defect.defInfo.maintenanceExplain')}}：</text>
								<text class="info-desc">{{item.changeDesp}}</text>
							</view>
							<view>
								<text class="info-title">{{$t('defect.common.applicant')}}：</text>
								<text class="info-desc">{{item.applyerName}}</text>
							</view>
						</view>
					</view>
					<view class="list-area" v-if="item.changeType == 'yqsq'">
						<view class="list-type">
							<view class="type">{{$t('defect.common.delay')}}</view>
						</view>
						<view class="list-info">
							<view>
								<text class="info-title">{{$t('defect.defInfo.postPoneTo')}}：</text>
								<text class="info-desc">{{item.changeTime}}</text>
							</view>
							<view>
								<text class="info-title">{{$t('defect.defInfo.postPoneReason')}}：</text>
								<text class="info-desc">{{item.changeDesp}}</text>
							</view>
						</view>
					</view>
					<view class="list-area" v-if="item.changeType == 'ylzesl'">
						<view class="list-type">
							<view class="type">{{$t('defect.common.downgrade')}}</view>
						</view>
						<view class="list-info">
							<view>
								<text class="info-title">{{$t('defect.defInfo.turnTTReason')}}：</text>
								<text class="info-desc">{{item.changeDesp}}</text>
							</view>
							<view>
								<text class="info-title">{{$t('defect.defInfo.turnTTRiskAssess')}}：</text>
								<text class="info-desc">{{item.risk}}</text>
							</view>
							<view>
								<text class="info-title">{{$t('defect.defInfo.turnTTMeasure')}}：</text>
								<text class="info-desc">{{item.applyedMeasure}}</text>
							</view>
						</view>
					</view>
					<view class="list-area" v-if="item.changeType == 'gqsq'">
						<view class="list-type">
							<view class="type">{{$t('defect.common.pending')}}</view>
						</view>
						<view class="list-info">
							<view>
								<text class="info-title">{{$t('defect.defInfo.hangUpReason')}}：</text>
								<text class="info-desc">{{item.changeDesp}}</text>
							</view>
							<view>
								<text class="info-title">{{$t('defect.defInfo.turnTTRiskAssess')}}：</text>
								<text class="info-desc">{{item.risk}}</text>
							</view>
							<view>
								<text class="info-title">{{$t('defect.defInfo.turnTTMeasure')}}：</text>
								<text class="info-desc">{{item.applyedMeasure}}</text>
							</view>
						</view>
					</view>
					<view class="list-area" v-if="item.changeType == 'nbbg'">
						<view class="list-type">
							<view class="type">{{$t('defect.common.turn')}}</view>
						</view>
						<view class="list-info">
							<view>
								<text class="info-title">{{$t('defect.defInfo.toMajorAndTeam')}}：</text>
								<text class="info-desc">{{item.toLevel | codeFormat(skillList)}}/{{item.toTeamName}}</text>
							</view>
							<view>
								<text class="info-title">{{$t('defect.defInfo.turnTTConesc')}}：</text>
								<text class="info-desc">{{item.changeDesp}}</text>
							</view>
							<view>
								<text class="info-title">{{$t('defect.common.applicant')}}：</text>
								<text class="info-desc">{{item.applyerName}} {{ item.applyTime}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		
		<!-- 开具工作票弹出框 -->
		<uni-popup ref="ticket" type="bottom" background-color="#fff">
			<scroll-view scroll-y="true" class="scroll-height-type">
				<uni-list>
					<uni-list-item 
						v-for="item in ticketTypes" 
						:key="item.wtTypeId" 
						:title="item.wtTypeName" 
						clickable 
						@click="issueTicket(item)">
					</uni-list-item>
				</uni-list>
			</scroll-view>
		</uni-popup>
	</view>
</template>

<script>
	import { getDefectLevel, getNotifierByLevel, addDefect } from '@/api/business/defect.js'
	import { getWorkTicketType, getWtTypePageById, getRolePersonById } from '@/api/business/ticket.js'
	import { addConectInfoApi } from '@/api/business/workorder.js'
	import { findByTypeKeyExtend, findByType, findByUserId, queryOrgManagerByOrgId, queryOrgListParameters } from '@/api/platform/common.js'
	import { getEqLocationInfo, getEqAreaById } from '@/api/base/equipment.js'
	import { getFaultReport } from '@/api/business/workorder.js'
	import { notice, utilities, business } from '@/utils/common.js'
	
	export default {
		props: {
			data: {
				type: Object,
				default() {
					return {}
				}
			},
			nfcData: {
				type: String
			},
			isNew: {
				type: Boolean,
				default: false
			},
			isEdit: {
				type: Boolean,
				default: false
			},
			isView: {
				type: Boolean,
				default: false
			},
			isApprove: {
				type: Boolean,
				default: false
			},
			defaultData: {
				type: Object,
				default() {
					return {}
				}
			},
			disableData: {
				type: Array,
				default() {
					return []
				}
			},
			editData: {
				type: Array,
				default() {
					return []
				}
			}
		},
		data() {
			return {
				dataOk: false,
				judgeBase: false, //判断基础信息是否禁用
				levelList: [],
				typeList: [],
				skillList: [],
				hangTimeList: [],
				teamList: [],
				radioList: [
					{ value: '1', label: this.$t('baseCommon.status.yes') },
					{ value: '0', label: this.$t('baseCommon.status.no') }
				],
				actualAnalyse: {},
				showAnalysis: true,
				showFold: false,
				ticketTypes: [],
			}
		},
		computed: {
			dfFaultKnowledge() {
				return utilities.getConfig('PROJECT').OPEN_DF_FAULT_KNOWLEDGE
			},
			dfWorkOrder() {
				return utilities.getConfig('PROJECT').OPEN_DF_WORK_ORDER
			},
			pageTicket() {
				return business.getPagePath('m_wt_create_fire')
			},
			dfMaterial() {
				return utilities.getConfig('PROJECT').OPEN_DF_MATERIAL
			}
		},
		mounted() {
			this.init()
		},
		watch: {
			nfcData: {
				handler(val) {
					this.handleNfc()
				},
				// immediate: true
			}
		},
		methods: {
			async init() {
				// 缺陷等级
				getDefectLevel().then(res=>{
					this.levelList = []
					const _this = this
					for (const [key, value] of Object.entries(res.data)) {
						_this.levelList.push({
							value: key,
							label: value
						})
					}
				})
				
				// 数据字典
				let typeKeys = "zybm,qxlx,gqsjsz"
				findByTypeKeyExtend(typeKeys).then(res=>{
					// 专业
					if(res.data && res.data.zybm) {
						res.data.zybm.forEach(item=>{
							this.skillList.push({
								value: item.key,
								label: item.name
							})
						})
					}
					// 缺陷类型
					if(res.data && res.data.qxlx) {
						res.data.qxlx.forEach(item=>{
							this.typeList.push({
								value: item.key,
								label: item.name
							})
						})
					}
					// 挂起时间设置
					if(res.data && res.data.gqsjsz) {
						res.data.gqsjsz.forEach(item=>{
							this.hangTimeList.push({
								value: item.key,
								label: item.name
							})
						})
					}
				})
				
				// 班组
				this.teamList = []
				let params = [
					{ key: "QA^org_type", value: "JX" }
				]
				queryOrgListParameters({ 'parameters': params}).then(res => {
					if (res.state === 200) {
						res.data.forEach(item=>{
							this.teamList.push({
								value: item.id,
								label: item.name
							})
						})
					}
				})
				
				// 判断基础信息是否禁用
				this.judgeBase = this.isView || (this.isApprove && !this.editData.includes('app_base'))
				// 判断页面是否折叠
				this.showFold = !this.disableData.includes('app_fold')
				// 判断缺陷分析是否展示
				if (this.defaultData.isReasonAnalysis){
					if (this.data.oldReasonAnalysis){
						this.showAnalysis = true
					}	else {
						this.showAnalysis = false
					}
				} else {
					this.showAnalysis = true
				}
				
				this.dataOk = true
			},
			dateChange(e, attr) {
				this.data[attr] = e
			},
			teamChange(e) {
				if(e) {
					this.data.mtnTeamName = this.teamList.find(r => r.value == e).label
				}
			},
			typeChange(e) {
				this.$emit('changeDfType')
			},
			radioChange(e, type) {
				if(type == 'type') {
					this.data.dfType = e.target.value
				} else if(type == 'replace') {
					this.data.isReplace = e.target.value
					addDefect({
						dfId: this.data.dfId,
						dfNo: this.data.dfNo,
						isReplace: this.data.isReplace
					})
				}
			},
			selectLevel(){
				getNotifierByLevel(this.data.dfLevelNo).then(res=>{
					this.data.noticepersonId = res.data.split("--")[0]
					this.data.noticeperson = res.data.split("--")[1]
					let timeLimit = res.data.split("--")[2]
					this.data.planEndTime = utilities.getCalDateTime(this.data.finddate, timeLimit)
				})
			},
			selectStdWo() {
				if(!this.data.oldEqTypeId){
					this.data.oldEqTypeId = ""
				}
				
				let that = this
				uni.navigateTo({
					url: '/pages/business/defect/common/select-std-wo?eqTypeId='+ that.data.oldEqTypeId +'&stdWoId=' + that.data.oldStdWoId,
					events: {
						selectStdWo(data) {
							that.data.oldStdWoId = data.stdWoId
							that.data.oldStdWoName = data.stdWoNo
						}
					}
				})
			},
			selectPhenomenon() {
				if(!this.data.locaNo){
					notice.toast(this.$t('baseCommon.message.pleaseSelect', { title: this.$t('defect.common.locaName') }))
					return
				}
				if(!this.data.oldEqTypeId){
					this.data.oldEqTypeId = ""
				}
				if(!this.data.assetTypeId) {
					this.data.assetTypeId = ""
				}
				
				let that = this
				uni.navigateTo({
					url: '/pages/business/defect/common/select-phenomenon?eqTypeId='+ that.data.oldEqTypeId +'&assetTypeId='+ that.data.assetTypeId +'&phenomenon=' + that.data.phenomenonId,
					events: {
						selectPhenomenon(data) {
							that.data.phenomenonId = data.id
							that.data.oldFaultCode = data.faultCode
							that.data.oldFaultDescription = data.faultDescription
							that.data.oldReasonAnalysis = data.reasonAnalysis
							that.data.oldTreatmentMeasure = data.treatmentMeasure
							that.data.oldStdWoId = data.stdWoId
							that.data.oldStdWoName = data.stdWoName
							that.autoDesp()
						}
					}
				})
			},
			autoDesp() {
				if (!this.data.dfId && this.data.source != 'woFault' && this.data.locaName && this.data.oldFaultDescription) {
					this.data.dfDesp = this.data.locaRealName + this.data.oldFaultDescription
				}
			},
			selectUser(type) {
				let that = this
				uni.navigateTo({
					url: '/pages/base/select-user?type='+type,
					events: {
						selectUser(type, user) {
							if(type == 'find') { // 发现人
								that.data.findpersonId = user.id
								that.data.findperson = user.name
								that.data.findTeamNo = user.groupID
								that.data.findTeamName = user.orgName
								let orgName = user.orgName.split(".")
								if (orgName.length > 0){
									that.data.findTeamName = orgName[orgName.length - 2]
								}
							} else if(type == 'solve') { // 消缺负责人
								that.data.mtnPersonId = user.id
								that.data.mtnPerson = user.name
								that.getMtnTeam()
							} else if(type == 'analysis') { // 分析人
								that.data.analysiserId = user.id
								that.data.analysiser = user.name
							}
						}
					}
				})
			},
			selectUserMulti(type) {
				let that = this
				uni.navigateTo({
					url: '/pages/base/select-user-multi?type=' + type + '&users=' + that.data.noticepersonId,
					events: {
						selectUserMulti(user) {
							let userIds =   []
							let userNames =  []
							user.forEach(item=>{
								if(!userIds.includes(item.userId)) {
									userIds.push(item.userId)
								}
								if(!userNames.includes(item.userName)) {
									userNames.push(item.userName)
								}
							})
							that.data.noticepersonId = userIds.join()
							that.data.noticeperson = userNames.join()
						}
					}
				})
			},
			scanLoca() {
				let that = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function (res) {
						let data = business.handleCode(res.result)
						let scanId = data.scanId
						
						// 根据设备位置查询设备信息
						that.getEqLocationInfo(scanId)
					}
				});
			},
			selectLoca() {
				let that = this
				uni.navigateTo({
					url: "/pages/base/equipment-location",
					events: {
						selectLoca(asset) {
							that.data.locaId = asset.locaId
							that.data.locaNo = asset.locaNo
							that.data.locaName = asset.manageObjName ? asset.manageObjName + "/" + asset.locaNo + "/" + asset.locaName : asset.locaNo + "/" + asset.locaName
							that.data.locaRealName = asset.locaName
							that.data.assetId = asset.assetId
							that.data.assetNo = asset.assetNo
							that.data.assetName = asset.assetName
							that.data.assetTypeId = asset.equipmentAssetPo ? asset.equipmentAssetPo.assetTypeId : ""
							that.data.assetTypeName = asset.assetTypeName
							that.data.manageObjNo = asset.manageObjId
							that.data.manageObjName = asset.manageObjName
							that.data.skillNo = asset.skillNo
							// that.data.skillName = asset.skillName
							that.data.skillName = that.data.skillNo ? that.skillList.find(r=>r.value == that.data.skillNo).label : ""
							that.data.operationTeamNo = asset.operationDeptNo
							that.data.operationTeamName = asset.operationDeptName
							that.autoDesp()
							
							//获取区域负责人
							if (asset.areaId){
								getEqAreaById(asset.areaId).then(res => {
									if (res.data){
										that.data.mtnPersonId = res.data.managerId
										that.data.mtnPerson = res.data.managerName
										that.getMtnTeam();
									}
								})
							}
						}
					}
				})
			},
			async getMtnTeam() {
				if (this.data.mtnPersonId) {
					let levelID
					await findByType({ 'type': 'org' }).then((ret) => {
						if (ret.state === 200) {
							ret.data.forEach(item => {
								if (item.name === '班组') {
									levelID = item.id
								}
							})
						}
					})
					
					findByUserId({ 'userId': this.data.mtnPersonId }).then(res => {
						if (res.state === 200) {
							res.data.forEach(item => {
								if (item.levelID === levelID) {
									this.data.mtnTeamNo = item.id
									this.data.mtnTeamName = item.name
									queryOrgManagerByOrgId({ 'OrgId': item.id }).then(ret => {
										if (ret.state === 200) {
											this.data.noticepersonId = ret.data.dataResult.length > 0 ? ret.data.dataResult[0].id : ""
											this.data.noticeperson = ret.data.dataResult.length > 0 ? ret.data.dataResult[0].name : ""
										}
									})
									return
								}
							})
						}
					})
				}
			},
			selectEqType() {
				let that = this
				uni.navigateTo({
					url: "/pages/business/defect/common/select-eqType?eqTypeId="+that.data.oldEqTypeId,
					events: {
						selectEqType(data) {
							that.data.oldEqTypeId = data.eqTypeId
							that.data.oldEqTypeName = data.eqTypeName
						}
					}
				})
			},
			commitViewLink(e) {
				let url
				if(e.boTypeNo == "wt_wt") {
					url = '/pages/business/ticket/workTicket/workTicketBase/index?type=view&id=' + e.boId
				} else if(e.boTypeNo == "ex_mat_use") {
					url = '/pages/business/material/collar/add?id=' + e.boId
				} else if(e.boTypeNo == "ex_mat_gb") {
					url = '/pages/business/material/back/add?id=' + e.boId
				}
				uni.navigateTo({
					url: url
				})
			},
			clickIcon() {
				this.showFold = !this.showFold
			},
			// 开具工作票
			async applyTicket() {
				let res = await getRolePersonById(uni.getStorageSync("userId"))
				if(res.data && res.data.isManager === "1") {
					this.showTooltip = false
					this.$refs.ticket.open()
					this.ticketTypes = []
					getWorkTicketType().then(res => {
						res.data.records.forEach(item => {
						  if (item.isOn == 1 && item.isMain == 1) {
						    this.ticketTypes.push({
						      wtTypeName: item.wtTypeName,
						      wtTypeId: item.wtTypeId,
							  wtTypeNo: item.wtTypeNo
						    })
						  }
						})
					})
				} else {
					notice.toast(this.$t('ticket.message.noPermisBil'))
					return
				}
			},
			async issueTicket(item) {
				this.$refs.ticket.close()
				
				let sourceData = {
					locaId: this.data.locaId,
					locaNo: this.data.locaNo,
					locaName: this.data.locaName,
					operationDeptId: this.data.operationTeamNo,
					operationDeptName: this.data.operationTeamName,
					relateDfId: this.data.dfId
				}
				
				let pages = await getWtTypePageById(item.wtTypeId)
				let url = pages.data.find(r => r.pageType == 'add').appPageUrl
				let that = this
				uni.navigateTo({
					url: url + '?wtTypeId=' + item.wtTypeId + "&type=add&source=defect&sourceData=" + JSON.stringify(sourceData),
					events: {
						eventData(obj) {
							addConectInfoApi({
								woId: that.data.woId,
								boTypeNo: "wt_wt",
								boId: obj.wtId,
								boNo: obj.wtNo,
								boContent: obj.workContent
							})
						}
					}
				})
			},
			async handleNfc() {
				if(this.nfcData) {
					let data = business.handleCode(this.nfcData)
					let scanId = data.scanId
					
					// 根据设备位置查询设备信息
					this.getEqLocationInfo(scanId)
				}
			},
			getEqLocationInfo(scanId) {
				getEqLocationInfo(scanId).then(res=>{
					if(res.data) {
						let asset = res.data
						this.data.locaId = asset.locaId
						this.data.locaNo = asset.locaNo
						this.data.locaName = asset.manageObjName ? asset.manageObjName + "/" + asset.locaNo + "/" + asset.locaName : asset.locaNo + "/" + asset.locaName
						this.data.locaRealName = asset.locaName
						this.data.assetId = asset.assetId
						this.data.assetNo = asset.assetNo
						this.data.assetName = asset.assetName
						this.data.assetTypeId = asset.equipmentAssetPo ? asset.equipmentAssetPo.assetTypeId : ""
						this.data.assetTypeName = asset.assetTypeName
						this.data.manageObjNo = asset.manageObjId
						this.data.manageObjName = asset.manageObjName
						this.data.skillNo = asset.skillNo
						// this.data.skillName = asset.skillName
						this.data.skillName = this.data.skillNo ? this.skillList.find(r=>r.value == this.data.skillNo).label : ""
						this.data.operationTeamNo = asset.operationDeptNo
						this.data.operationTeamName = asset.operationDeptName
						this.autoDesp()
						
						//获取区域负责人
						if (asset.areaId){
							getEqAreaById(asset.areaId).then(res => {
								if (res.data){
									this.data.mtnPersonId = res.data.managerId
									this.data.mtnPerson = res.data.managerName
									this.getMtnTeam();
								}
							})
						}
					} else {
						notice.toast(this.$t('inspection.message.notQueryEquipment'))
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/style/common-detail.scss';
	
	.scroll-height {
		/* #ifdef APP-PLUS */
		height: calc(100vh - 110px);
		/* #endif*/
		/* #ifdef H5 */
		height: calc(100vh - 155px);
		/* #endif*/
	}
	
	.scroll-height-fold {
		/* #ifdef APP-PLUS */
		height: calc(100vh - 140px);
		/* #endif*/
		/* #ifdef H5 */
		height: calc(100vh - 190px);
		/* #endif*/
	}
	
	.shortleft {
		width: 25%;
	}
	
	.fieldSplice {
		width: 75%;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		
		input {
			width: 60px;
		}
		
		.separator {
			margin: 0 5px;
		}
		
		.fieldView {
			line-height: 35px;
		}
	}

	uni-radio-group {
	    display: inline-flex;
	}
	
	.radio-label {
		display: flex;
		margin: 0 5px;
	}
	
	.radio-item {
		transform: scale(0.7);
	}
	
	.fold-icon {
		text-align: right;
		
		uni-image {
			width: 40px;
			height: 30px;
		}
	}
	
	.scroll-height-type {
		max-height: 350px;
	}
</style>
